#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include "serverconfig.h"
#include "connector.h"
#include "QMap"
#include "httpparser.h"
/**
 * 服务器类
 * @brief The Server class
 */
class Server : public QObject
{
    Q_OBJECT
public:
    explicit Server(QObject *parent);
    ~Server()override;
    /**
     * 启动服务器
     * @brief start
     * @param config 配置为空则采用默认配置
     */
    bool start(ServerConfig * config = nullptr);
    /**
     * 停止服务器
     * @brief stop
     */
    void stop();
signals:

public slots:
    /**
     * 新的连接到达
     * @brief newConnection
     * @param conn
     */
    void newConnection(Connection * conn);
    /**
     * 有数据可读
     * @brief slotReadClientData
     */
    void slotReadClientData(Connection *conn);
    /**
     * 连接断开
     * @brief slotClientDisconnected
     */
    void slotClientDisconnected(Connection *conn);
private:
    //配置
    ServerConfig * config = nullptr;
    //连接器
    Connector * connector = nullptr;
    //所有的连接
    QMap<QString, Connection *> * connections;
    //http协议解析器
    HttpParser * httpParser =  nullptr;

    QString createMapKey(Connection * conn);

};

#endif // SERVER_H
